package com.pay.plat.controller;

import java.io.IOException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.image.common.RestUploadFileInfo;
import com.pay.constant.PathConstant;
import com.pay.plat.mapping.MappingUtils;
import com.pay.utils.ResponseData;

@Controller
public class FileController {

	@ResponseBody
	@RequestMapping(value=MappingUtils.upload,method= {RequestMethod.POST})
	public ResponseData upload(MultipartFile file) throws IOException {
		if(file == null) {
			return ResponseData.baseError("上传失败") ;
		}
		RestUploadFileInfo upload = com.image.common.Service.uploadImage(file.getOriginalFilename(), file.getInputStream(), PathConstant.bank_image);
		if(upload.isStatus()) {
			return ResponseData.ok().putDataValue("imagePath", upload.getServiceName() + upload.getFilePath() + upload.getFileName()) ;
		}else {
			return ResponseData.baseError("图片上传失败") ;
		}
	}
}
